/*
 * Copyright (C) 2016 The Android Open Source Project
 *  Created by  Ant  2016/9/1  18:07
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ant.cn.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by baichuan on 2016/9/1.
 */
public class FileUtils {
    public static FileOutputStream fout;
    public static FileInputStream fin;

    public static void file2sd(File file, String dirpaht) {
        try {
            fout = new FileOutputStream(new File(dirpaht));
            fin = new FileInputStream(file);
            byte[] by = new byte[1024];
            int count=0;
            while ((count=fin.read(by) )> 0) {
                fout.write(by,0,count);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

            try {
                if (fout != null) {
                    fout.flush();
                    fout.close();
                }

                if (fin != null) {
                    fin.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
